diff options
author | Alexis Ballier <aballier@gentoo.org> | 2013-08-02 09:38:36 -0400 |
---|---|---|
committer | Alexis Ballier <aballier@gentoo.org> | 2013-08-06 10:17:06 -0400 |
commit | 9441222993e58e1ba71fb12faac31fbfe78bdd3f (patch) | |
tree | 35671794b4635408b3c9c20e64980db6c1da62cd | |
parent | fb1bd7e4c4a723436d7e8e26862d90a0347a4d08 (diff) |
Introduce a libav-hacks library to wrap a compatibility layer with libav.
This copies/pastes some code from FFmpeg but at least allows us to support the fork.
-rw-r--r-- | Makefile.in | 4 | ||||
-rw-r--r-- | lib/DllAvUtil.h | 3 | ||||
-rw-r--r-- | lib/DllSwResample.h | 6 | ||||
-rw-r--r-- | lib/xbmc-libav-hacks/Makefile | 6 | ||||
-rw-r--r-- | lib/xbmc-libav-hacks/accessors.c | 35 | ||||
-rw-r--r-- | lib/xbmc-libav-hacks/alloc_output_context2.c | 80 | ||||
-rw-r--r-- | lib/xbmc-libav-hacks/buffersink.c | 36 | ||||
-rw-r--r-- | lib/xbmc-libav-hacks/libav_hacks.h | 81 | ||||
-rw-r--r-- | lib/xbmc-libav-hacks/swresample.c | 75 |
9 files changed, 325 insertions, 1 deletions
diff --git a/Makefile.in b/Makefile.in index 6a3792f54f..a66945e97b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -174,6 +174,10 @@ ifeq (@USE_OMXPLAYER@,1) DIRECTORY_ARCHIVES += xbmc/cores/omxplayer/omxplayer.a endif +ifeq (@USE_LIBAV_HACKS@,1) +DIRECTORY_ARCHIVES += lib/xbmc-libav-hacks/dll-libavhacks.a +endif + PAPCODECS_DIRS= \ lib/xbadpcm \ lib/nosefart \ diff --git a/lib/DllAvUtil.h b/lib/DllAvUtil.h index 74039d9c70..71900c5b6c 100644 --- a/lib/DllAvUtil.h +++ b/lib/DllAvUtil.h @@ -46,6 +46,9 @@ extern "C" { #include <libavutil/opt.h> #include <libavutil/mem.h> #include <libavutil/mathematics.h> + #if (defined USE_LIBAV_HACKS) + #include "xbmc-libav-hacks/libav_hacks.h" + #endif #else #include "libavutil/avutil.h" //for av_get_default_channel_layout diff --git a/lib/DllSwResample.h b/lib/DllSwResample.h index 686aec6411..1981d512af 100644 --- a/lib/DllSwResample.h +++ b/lib/DllSwResample.h @@ -37,7 +37,11 @@ extern "C" { #pragma warning(disable:4244) #endif #if (defined USE_EXTERNAL_FFMPEG) - #include <libswresample/swresample.h> + #if (defined USE_LIBAV_HACKS) + #include "xbmc-libav-hacks/libav_hacks.h" + #else + #include <libswresample/swresample.h> + #endif #else #include "libswresample/swresample.h" #endif diff --git a/lib/xbmc-libav-hacks/Makefile b/lib/xbmc-libav-hacks/Makefile new file mode 100644 index 0000000000..463a9081fd --- /dev/null +++ b/lib/xbmc-libav-hacks/Makefile @@ -0,0 +1,6 @@ +SRCS = swresample.c alloc_output_context2.c buffersink.c accessors.c + +LIB = dll-libavhacks.a + +include ../../Makefile.include +-include $(patsubst %.cpp,%.P,$(patsubst %.c,%.P,$(SRCS))) diff --git a/lib/xbmc-libav-hacks/accessors.c b/lib/xbmc-libav-hacks/accessors.c new file mode 100644 index 0000000000..a2997113a4 --- /dev/null +++ b/lib/xbmc-libav-hacks/accessors.c @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2005-2013 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 + * + */ + +#include "libav_hacks.h" + +AVDictionary *av_frame_get_metadata (const AVFrame *frame) +{ + return NULL; +} + +AVRational av_stream_get_r_frame_rate(const AVStream *s) +{ + AVRational zero; + zero.num = 0; + zero.den = 1; + return zero; +} diff --git a/lib/xbmc-libav-hacks/alloc_output_context2.c b/lib/xbmc-libav-hacks/alloc_output_context2.c new file mode 100644 index 0000000000..b0aa5eb4dd --- /dev/null +++ b/lib/xbmc-libav-hacks/alloc_output_context2.c @@ -0,0 +1,80 @@ +/* + * Code copied from libavformat/mux.c + * + * Original license is: + * + * Copyright (c) 2000, 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 "libav_hacks.h" + +#include <libavutil/avstring.h> + +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; +} diff --git a/lib/xbmc-libav-hacks/buffersink.c b/lib/xbmc-libav-hacks/buffersink.c new file mode 100644 index 0000000000..e3fdd35e73 --- /dev/null +++ b/lib/xbmc-libav-hacks/buffersink.c @@ -0,0 +1,36 @@ +/* + * Code copied from libavfilter/buffersink.c + * + * Original license is: + * + * 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 + */ + +#include "libav_hacks.h" + +AVBufferSinkParams *av_buffersink_params_alloc(void) +{ + static const int pixel_fmts[] = { AV_PIX_FMT_NONE }; + AVBufferSinkParams *params = av_malloc(sizeof(AVBufferSinkParams)); + if (!params) + return NULL; + + params->pixel_fmts = pixel_fmts; + return params; +} diff --git a/lib/xbmc-libav-hacks/libav_hacks.h b/lib/xbmc-libav-hacks/libav_hacks.h new file mode 100644 index 0000000000..84ae3d0605 --- /dev/null +++ b/lib/xbmc-libav-hacks/libav_hacks.h @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2005-2013 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 + * + */ + +#ifndef __LIBAV_HACKS_H +#define __LIBAV_HACKS_H + +#include <libavutil/avutil.h> +#include <libavutil/opt.h> +#include <libavresample/avresample.h> +#include <libavformat/avformat.h> + +#if LIBAVUTIL_VERSION_MICRO >= 100 +#error "You should not enable libav hacks when building against FFmpeg." +#endif + +#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(52,8,0) +#error "Your libav version is too old. Please update to libav-10 or git master." +#endif + +// libavutil + +#define AV_CODEC_ID_OTF AV_CODEC_ID_TTF + +AVDictionary *av_frame_get_metadata (const AVFrame *frame); + +// libavformat + +int avformat_alloc_output_context2(AVFormatContext **ctx, AVOutputFormat *oformat, + const char *format_name, const char *filename); + +AVRational av_stream_get_r_frame_rate(const AVStream *s); + +// libavresample + +#define SwrContext AVAudioResampleContext + +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); + +int swr_init(struct SwrContext *s); + +void swr_free(struct SwrContext **s); + +int swr_convert(struct SwrContext *s, uint8_t **out, int out_count, + const uint8_t **in , int in_count); + +int64_t swr_get_delay(struct SwrContext *s, int64_t base); + +int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map); + +int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride); + +// libavfilter + +typedef struct { + const enum AVPixelFormat *pixel_fmts; ///< list of allowed pixel formats, terminated by AV_PIX_FMT_NONE +} AVBufferSinkParams; + +AVBufferSinkParams *av_buffersink_params_alloc(void); + +#endif diff --git a/lib/xbmc-libav-hacks/swresample.c b/lib/xbmc-libav-hacks/swresample.c new file mode 100644 index 0000000000..44e52190c3 --- /dev/null +++ b/lib/xbmc-libav-hacks/swresample.c @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2005-2013 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 + * + */ + +#include "libav_hacks.h" + +#include <libavutil/mathematics.h> +#include <libavutil/opt.h> + +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) +{ + AVAudioResampleContext *ret = avresample_alloc_context(); + av_opt_set_int(ret, "out_channel_layout", out_ch_layout , 0); + av_opt_set_int(ret, "out_sample_fmt" , out_sample_fmt , 0); + av_opt_set_int(ret, "out_sample_rate" , out_sample_rate, 0); + av_opt_set_int(ret, "in_channel_layout" , in_ch_layout , 0); + av_opt_set_int(ret, "in_sample_fmt" , in_sample_fmt , 0); + av_opt_set_int(ret, "in_sample_rate" , in_sample_rate , 0); + return ret; +} + + +int swr_init(struct SwrContext *s) +{ + return avresample_open(s); +} + +void swr_free(struct SwrContext **s) +{ + avresample_close(*s); + *s = NULL; +} + +int swr_convert(struct SwrContext *s, uint8_t **out, int out_count, + const uint8_t **in , int in_count) +{ + return avresample_convert(s, out, 0, out_count, (uint8_t**)in, 0,in_count); +} + +int64_t swr_get_delay(struct SwrContext *s, int64_t base) +{ + int64_t in_sr; + av_opt_get_int(s, "in_sample_rate", 0, &in_sr); + return avresample_available(s) + av_rescale_rnd(avresample_get_delay(s), base, in_sr, AV_ROUND_UP); +} + +int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map) +{ + return avresample_set_channel_mapping(s, channel_map); +} + +int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride) +{ + return avresample_set_matrix(s, matrix, stride); +} |