# Patch to fix compatibility with FFmpeg 3.x
# See https://gitweb.gentoo.org/repo/gentoo.git/tree/media-video/vlc/files/vlc-2.2.4-ffmpeg3.patch
# See https://gitweb.gentoo.org/repo/gentoo.git/tree/media-video/vlc/files/vlc-2.2.4-libav-11.7.patch
# See https://gitweb.gentoo.org/repo/gentoo.git/tree/media-video/vlc/files/vlc-2.2.4-relax_ffmpeg.patch
# See https://gitweb.gentoo.org/repo/gentoo.git/tree/media-video/vlc/files/vlc-2.2.8-libupnp-compat.patch
diff -urNad vlc-2.2.8-orig/configure.ac vlc-2.2.8/configure.ac
--- vlc-2.2.8-orig/configure.ac	2017-11-21 20:35:05.000000000 +0200
+++ vlc-2.2.8/configure.ac	2018-01-21 14:19:56.895278615 +0200
@@ -2317,8 +2317,8 @@
 [  --enable-avcodec        libavcodec codec (default enabled)])
 AS_IF([test "${enable_avcodec}" != "no"], [
   PKG_CHECK_MODULES(AVCODEC,[libavcodec >= 53.34.0 libavutil >= 51.22.0], [
-    PKG_CHECK_EXISTS([libavutil < 55],, [
-      AC_MSG_ERROR([libavutil versions 55 and later are not supported.])
+    PKG_CHECK_EXISTS([libavutil < 56],, [
+      AC_MSG_ERROR([libavutil versions 56 and later are not supported.])
     ])
     VLC_SAVE_FLAGS
     CPPFLAGS="${CPPFLAGS} ${AVCODEC_CFLAGS}"
@@ -2377,7 +2377,9 @@
   case "${avfork}" in
     ffmpeg)
       PKG_CHECK_EXISTS([libavcodec >= 57.10.100], [
-        AC_MSG_ERROR([VA API requires FFmpeg libavcodec < 57.10 or libav.])
+        PKG_CHECK_EXISTS([libavcodec <= 57.12.100], [
+          AC_MSG_ERROR([VA API requires FFmpeg libavcodec < 57.10 or > 57.12 or libav.])
+        ])
       ])
       ;;
   esac
@@ -2411,7 +2413,9 @@
     case "${avfork}" in
       ffmpeg)
         PKG_CHECK_EXISTS([libavcodec >= 57.10.100], [
-          AC_MSG_ERROR([DXVA2 requires FFmpeg libavcodec < 57.10 or libav.])
+          PKG_CHECK_EXISTS([libavcodec <= 57.12.100], [
+            AC_MSG_ERROR([DXVA2 requires FFmpeg libavcodec < 57.10 or > 57.12 or libav.])
+          ])
         ])
         ;;
     esac
@@ -3175,7 +3179,9 @@
     libav) av_vdpau_ver="55.26.0" ;;
     ffmpeg) av_vdpau_ver="55.42.100"
       PKG_CHECK_EXISTS([libavcodec >= 57.10.100], [
-        AC_MSG_ERROR([VDPAU requires FFmpeg libavcodec < 57.10 or libav.])
+        PKG_CHECK_EXISTS([libavcodec <= 57.12.100], [
+          AC_MSG_ERROR([VDPAU requires FFmpeg libavcodec < 57.10 or > 57.12 or libav.])
+        ])
       ])
       ;;
   esac
diff -urNad vlc-2.2.8-orig/modules/codec/avcodec/audio.c vlc-2.2.8/modules/codec/avcodec/audio.c
--- vlc-2.2.8-orig/modules/codec/avcodec/audio.c	2015-12-08 18:18:56.000000000 +0200
+++ vlc-2.2.8/modules/codec/avcodec/audio.c	2018-01-21 14:26:16.987941850 +0200
@@ -36,12 +36,13 @@
 #include <vlc_codec.h>
 #include <vlc_avcodec.h>
 
+#include "avcodec.h"
+
 #include <libavcodec/avcodec.h>
 #include <libavutil/mem.h>
 
-#include <libavutil/audioconvert.h>
+#include <libavutil/channel_layout.h>
 
-#include "avcodec.h"
 
 /*****************************************************************************
  * decoder_sys_t : decoder descriptor
diff -urNad vlc-2.2.8-orig/modules/codec/avcodec/encoder.c vlc-2.2.8/modules/codec/avcodec/encoder.c
--- vlc-2.2.8-orig/modules/codec/avcodec/encoder.c	2015-10-21 19:36:45.000000000 +0300
+++ vlc-2.2.8/modules/codec/avcodec/encoder.c	2018-01-21 14:19:56.992270368 +0200
@@ -41,7 +41,6 @@
 #include <vlc_cpu.h>
 
 #include <libavcodec/avcodec.h>
-#include <libavutil/audioconvert.h>
 
 #include "avcodec.h"
 #include "avcommon.h"
@@ -311,7 +310,7 @@
     else if( !GetFfmpegCodec( p_enc->fmt_out.i_codec, &i_cat, &i_codec_id,
                              &psz_namecodec ) )
     {
-        if( FindFfmpegChroma( p_enc->fmt_out.i_codec ) == PIX_FMT_NONE )
+        if( FindFfmpegChroma( p_enc->fmt_out.i_codec ) == AV_PIX_FMT_NONE )
             return VLC_EGENERIC; /* handed chroma output */
 
         i_cat      = VIDEO_ES;
@@ -555,7 +554,7 @@
 
         if( p_codec->pix_fmts )
         {
-            const enum PixelFormat *p = p_codec->pix_fmts;
+            const enum AVPixelFormat *p = p_codec->pix_fmts;
             for( ; *p != -1; p++ )
             {
                 if( *p == p_context->pix_fmt ) break;
@@ -1017,7 +1016,7 @@
         }
     }
 
-    p_sys->frame = avcodec_alloc_frame();
+    p_sys->frame = av_frame_alloc();
     if( !p_sys->frame )
     {
         goto error;
@@ -1088,7 +1087,7 @@
     AVFrame *frame = NULL;
     if( likely(p_pict) ) {
         frame = p_sys->frame;
-        avcodec_get_frame_defaults( frame );
+        av_frame_unref( frame );
         for( i_plane = 0; i_plane < p_pict->i_planes; i_plane++ )
         {
             p_sys->frame->data[i_plane] = p_pict->p[i_plane].p_pixels;
@@ -1329,7 +1328,7 @@
     //How much we need to copy from new packet
     const int leftover = leftover_samples * p_sys->p_context->channels * p_sys->i_sample_bytes;
 
-    avcodec_get_frame_defaults( p_sys->frame );
+    av_frame_unref( p_sys->frame );
     p_sys->frame->format     = p_sys->p_context->sample_fmt;
     p_sys->frame->nb_samples = leftover_samples + p_sys->i_samples_delay;
 
@@ -1451,7 +1450,7 @@
     while( ( p_aout_buf->i_nb_samples >= p_sys->i_frame_size ) ||
            ( p_sys->b_variable && p_aout_buf->i_nb_samples ) )
     {
-        avcodec_get_frame_defaults( p_sys->frame );
+        av_frame_unref( p_sys->frame );
         if( p_sys->b_variable )
             p_sys->frame->nb_samples = p_aout_buf->i_nb_samples;
         else
diff -urNad vlc-2.2.8-orig/modules/codec/avcodec/vaapi.c vlc-2.2.8/modules/codec/avcodec/vaapi.c
--- vlc-2.2.8-orig/modules/codec/avcodec/vaapi.c	2014-11-16 20:57:58.000000000 +0200
+++ vlc-2.2.8/modules/codec/avcodec/vaapi.c	2018-01-21 14:19:57.076263227 +0200
@@ -595,7 +595,7 @@
         return err;
 
     /* Only VLD supported */
-    p_va->pix_fmt = PIX_FMT_VAAPI_VLD;
+    p_va->pix_fmt = AV_PIX_FMT_VAAPI_VLD;
     p_va->setup = Setup;
     p_va->get = Get;
     p_va->release = Release;
diff -urNad vlc-2.2.8-orig/modules/codec/avcodec/video.c vlc-2.2.8/modules/codec/avcodec/video.c
--- vlc-2.2.8-orig/modules/codec/avcodec/video.c	2017-07-13 12:16:59.000000000 +0300
+++ vlc-2.2.8/modules/codec/avcodec/video.c	2018-01-21 14:19:57.209251921 +0200
@@ -108,8 +108,8 @@
 static int  ffmpeg_GetFrameBuf    ( struct AVCodecContext *, AVFrame * );
 static void ffmpeg_ReleaseFrameBuf( struct AVCodecContext *, AVFrame * );
 #endif
-static enum PixelFormat ffmpeg_GetFormat( AVCodecContext *,
-                                          const enum PixelFormat * );
+static enum AVPixelFormat ffmpeg_GetFormat( AVCodecContext *,
+                                          const enum AVPixelFormat * );
 
 static uint32_t ffmpeg_CodecTag( vlc_fourcc_t fcc )
 {
@@ -236,7 +236,7 @@
     p_sys->p_codec = p_codec;
     p_sys->i_codec_id = i_codec_id;
     p_sys->psz_namecodec = psz_namecodec;
-    p_sys->p_ff_pic = avcodec_alloc_frame();
+    p_sys->p_ff_pic = av_frame_alloc();
     p_sys->b_delayed_open = true;
     p_sys->p_va = NULL;
     vlc_sem_init( &p_sys->sem_mt, 0 );
@@ -448,7 +448,7 @@
     if( ffmpeg_OpenCodec( p_dec ) < 0 )
     {
         msg_Err( p_dec, "cannot open codec (%s)", p_sys->psz_namecodec );
-        avcodec_free_frame( &p_sys->p_ff_pic );
+        av_frame_free( &p_sys->p_ff_pic );
         vlc_sem_destroy( &p_sys->sem_mt );
         free( p_sys );
         return VLC_EGENERIC;
@@ -849,7 +849,7 @@
     wait_mt( p_sys );
 
     if( p_sys->p_ff_pic )
-        avcodec_free_frame( &p_sys->p_ff_pic );
+        av_frame_free( &p_sys->p_ff_pic );
 
     if( p_sys->p_va )
         vlc_va_Delete( p_sys->p_va );
@@ -1336,8 +1336,8 @@
 }
 #endif
 
-static enum PixelFormat ffmpeg_GetFormat( AVCodecContext *p_context,
-                                          const enum PixelFormat *pi_fmt )
+static enum AVPixelFormat ffmpeg_GetFormat( AVCodecContext *p_context,
+                                          const enum AVPixelFormat *pi_fmt )
 {
     decoder_t *p_dec = p_context->opaque;
     decoder_sys_t *p_sys = p_dec->p_sys;
diff -urNad vlc-2.2.8-orig/modules/services_discovery/upnp.cpp vlc-2.2.8/modules/services_discovery/upnp.cpp
--- vlc-2.2.8-orig/modules/services_discovery/upnp.cpp	2017-09-07 13:26:08.000000000 +0300
+++ vlc-2.2.8/modules/services_discovery/upnp.cpp	2018-01-21 17:46:27.612629147 +0200
@@ -40,7 +40,7 @@
 #include <assert.h>
 #include <limits.h>
 
-#if UPNP_VERSION < 10800
+#if UPNP_VERSION < 10623
 /*
  * Compat functions and typedefs for libupnp prior to 1.8
  */
@@ -75,7 +75,7 @@
   return p_s->Sid;
 }
 #else
-typedef const void* UpnpEventPtr;
+typedef void* UpnpEventPtr;
 #endif
 
 /*
