Introduce a libav-hacks library to wrap a compatibility layer with libav.
authorAlexis Ballier <aballier@gentoo.org>
Fri, 2 Aug 2013 13:38:36 +0000 (09:38 -0400)
committerAlexis Ballier <aballier@gentoo.org>
Tue, 6 Aug 2013 14:17:06 +0000 (10:17 -0400)
This copies/pastes some code from FFmpeg but at least allows us to support the fork.

Makefile.in
lib/DllAvUtil.h
lib/DllSwResample.h
lib/xbmc-libav-hacks/Makefile [new file with mode: 0644]
lib/xbmc-libav-hacks/accessors.c [new file with mode: 0644]
lib/xbmc-libav-hacks/alloc_output_context2.c [new file with mode: 0644]
lib/xbmc-libav-hacks/buffersink.c [new file with mode: 0644]
lib/xbmc-libav-hacks/libav_hacks.h [new file with mode: 0644]
lib/xbmc-libav-hacks/swresample.c [new file with mode: 0644]

index 6a3792f..a66945e 100644 (file)
@@ -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 \
index 74039d9..71900c5 100644 (file)
@@ -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
index 686aec6..1981d51 100644 (file)
@@ -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 (file)
index 0000000..463a908
--- /dev/null
@@ -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 (file)
index 0000000..a299711
--- /dev/null
@@ -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 (file)
index 0000000..b0aa5eb
--- /dev/null
@@ -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 (file)
index 0000000..e3fdd35
--- /dev/null
@@ -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 (file)
index 0000000..84ae3d0
--- /dev/null
@@ -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 (file)
index 0000000..44e5219
--- /dev/null
@@ -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);
+}