Readded AVRESAMPLE support as fallback.
authorArmin Novak <armin.novak@thincast.com>
Thu, 4 Oct 2018 06:57:54 +0000 (08:57 +0200)
committerArmin Novak <armin.novak@thincast.com>
Thu, 4 Oct 2018 07:16:34 +0000 (09:16 +0200)
cmake/FindFFmpeg.cmake
config.h.in
libfreerdp/codec/dsp_ffmpeg.c
packaging/deb/freerdp-nightly/control
packaging/rpm/freerdp-nightly.spec

index 08f4659..99dc779 100644 (file)
@@ -13,6 +13,7 @@ include(FindPkgConfig)
 if (PKG_CONFIG_FOUND)
        pkg_check_modules(AVCODEC libavcodec)
        pkg_check_modules(AVUTIL libavutil)
+       pkg_check_modules(AVRESAMPLE libavresample)
        pkg_check_modules(SWRESAMPLE libswresample)
 endif(PKG_CONFIG_FOUND)
 
@@ -28,17 +29,24 @@ find_library(AVUTIL_LIBRARY avutil PATHS ${AVUTIL_LIBRARY_DIRS})
 find_path(SWRESAMPLE_INCLUDE_DIR libswresample/swresample.h PATHS ${SWRESAMPLE_INCLUDE_DIRS})
 find_library(SWRESAMPLE_LIBRARY swresample PATHS ${SWRESAMPLE_LIBRARY_DIRS})
 
+# avresample
+find_path(AVRESAMPLE_INCLUDE_DIR libavresample/avresample.h PATHS ${AVRESAMPLE_INCLUDE_DIRS})
+find_library(AVRESAMPLE_LIBRARY avresample PATHS ${AVRESAMPLE_LIBRARY_DIRS})
 
-if (AVCODEC_INCLUDE_DIR AND AVCODEC_LIBRARY AND SWRESAMPLE_LIBRARY)
+if (AVCODEC_INCLUDE_DIR AND AVCODEC_LIBRARY)
        set(AVCODEC_FOUND TRUE)
-endif(AVCODEC_INCLUDE_DIR AND AVCODEC_LIBRARY AND SWRESAMPLE_LIBRARY)
+endif(AVCODEC_INCLUDE_DIR AND AVCODEC_LIBRARY)
 
 if (AVUTIL_INCLUDE_DIR AND AVUTIL_LIBRARY)
        set(AVUTIL_FOUND TRUE)
 endif(AVUTIL_INCLUDE_DIR AND AVUTIL_LIBRARY)
 
 include(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(FFmpeg DEFAULT_MSG AVUTIL_FOUND AVCODEC_FOUND SWRESAMPLE_FOUND)
+if (SWRESAMPLE_FOUND)
+       FIND_PACKAGE_HANDLE_STANDARD_ARGS(FFmpeg DEFAULT_MSG AVUTIL_FOUND AVCODEC_FOUND SWRESAMPLE_FOUND)
+else()
+       FIND_PACKAGE_HANDLE_STANDARD_ARGS(FFmpeg DEFAULT_MSG AVUTIL_FOUND AVCODEC_FOUND AVRESAMPLE_FOUND)
+endif()
 
 if (AVCODEC_VERSION)
        if (${AVCODEC_VERSION} VERSION_LESS ${REQUIRED_AVCODEC_API_VERSION})
@@ -50,8 +58,13 @@ else(AVCODEC_VERSION)
 endif(AVCODEC_VERSION)
 
 if (FFMPEG_FOUND)
-       set(FFMPEG_INCLUDE_DIRS ${AVCODEC_INCLUDE_DIR} ${AVUTIL_INCLUDE_DIR} ${SWRESAMPLE_INCLUDE_DIR})
-       set(FFMPEG_LIBRARIES ${AVCODEC_LIBRARY} ${AVUTIL_LIBRARY} ${SWRESAMPLE_LIBRARY})
+       if (SWRESAMPLE_FOUND)
+               set(FFMPEG_INCLUDE_DIRS ${AVCODEC_INCLUDE_DIR} ${AVUTIL_INCLUDE_DIR} ${SWRESAMPLE_INCLUDE_DIR})
+               set(FFMPEG_LIBRARIES ${AVCODEC_LIBRARY} ${AVUTIL_LIBRARY} ${SWRESAMPLE_LIBRARY})
+       elseif (AVRESAMPLE_FOUND)
+               set(FFMPEG_INCLUDE_DIRS ${AVCODEC_INCLUDE_DIR} ${AVUTIL_INCLUDE_DIR} ${AVRESAMPLE_INCLUDE_DIR})
+               set(FFMPEG_LIBRARIES ${AVCODEC_LIBRARY} ${AVUTIL_LIBRARY} ${AVRESAMPLE_LIBRARY})
+       endif()
 endif(FFMPEG_FOUND)
 
 mark_as_advanced(FFMPEG_INCLUDE_DIRS FFMPEG_LIBRARIES)
index 34aa7ce..26bc059 100644 (file)
@@ -27,6 +27,8 @@
 
 /* Features */
 #cmakedefine HAVE_ALIGNED_REQUIRED
+#cmakedefine SWRESAMPLE_FOUND
+#cmakedefine AVRESAMPLE_FOUND
 
 /* Options */
 #cmakedefine WITH_PROFILER
index bcde25b..5078cc2 100644 (file)
 #include <libavcodec/avcodec.h>
 #include <libavutil/avutil.h>
 #include <libavutil/opt.h>
+#if defined(SWRESAMPLE_FOUND)
 #include <libswresample/swresample.h>
+#elif defined(AVRESAMPLE_FOUND)
+#include <libavresample/avresample.h>
+#else
+#error "libswresample or libavresample required"
+#endif
 
 #include "dsp.h"
 #include "dsp_ffmpeg.h"
@@ -50,7 +56,11 @@ struct _FREERDP_DSP_CONTEXT
        AVFrame* resampled;
        AVFrame* buffered;
        AVPacket* packet;
+#if defined(SWRESAMPLE_FOUND)
        SwrContext* rcontext;
+#else
+       AVAudioResampleContext* rcontext;
+#endif
 };
 
 static BOOL ffmpeg_codec_is_filtered(enum AVCodecID id, BOOL encoder)
@@ -185,7 +195,13 @@ static void ffmpeg_close_context(FREERDP_DSP_CONTEXT* context)
                        av_packet_free(&context->packet);
 
                if (context->rcontext)
+               {
+#if defined(SWRESAMPLE_FOUND)
                        swr_free(&context->rcontext);
+#else
+                       avresample_free(&context->rcontext);
+#endif
+               }
 
                context->id = AV_CODEC_ID_NONE;
                context->codec = NULL;
@@ -281,7 +297,11 @@ static BOOL ffmpeg_open_context(FREERDP_DSP_CONTEXT* context)
        if (!context->buffered)
                goto fail;
 
-       context->rcontext = swr_alloc;
+#if defined(SWRESAMPLE_FOUND)
+       context->rcontext = swr_alloc();
+#else
+       context->rcontext = avresample_alloc_context();
+#endif
 
        if (!context->rcontext)
                goto fail;
@@ -322,6 +342,8 @@ fail:
        ffmpeg_close_context(context);
        return FALSE;
 }
+
+#if defined(SWRESAMPLE_FOUND)
 static BOOL ffmpeg_resample_frame(SwrContext* context,
                                   AVFrame* in, AVFrame* out)
 {
@@ -353,6 +375,40 @@ static BOOL ffmpeg_resample_frame(SwrContext* context,
 
        return TRUE;
 }
+#else
+static BOOL ffmpeg_resample_frame(AVAudioResampleContext* context,
+                                  AVFrame* in, AVFrame* out)
+{
+       int ret;
+
+       if (!avresample_is_open(context))
+       {
+               if ((ret = avresample_config(context, out, in)) < 0)
+               {
+                       const char* err = av_err2str(ret);
+                       WLog_ERR(TAG, "Error during resampling %s [%d]", err, ret);
+                       return FALSE;
+               }
+
+               if ((ret = (avresample_open(context))) < 0)
+               {
+                       const char* err = av_err2str(ret);
+                       WLog_ERR(TAG, "Error during resampling %s [%d]", err, ret);
+                       return FALSE;
+               }
+       }
+
+       if ((ret = avresample_convert_frame(context, out, in)) < 0)
+       {
+               const char* err = av_err2str(ret);
+               WLog_ERR(TAG, "Error during resampling %s [%d]", err, ret);
+               return FALSE;
+       }
+
+       return TRUE;
+}
+#endif
+
 static BOOL ffmpeg_encode_frame(AVCodecContext* context, AVFrame* in,
                                 AVPacket* packet, wStream* out)
 {
@@ -414,10 +470,17 @@ static BOOL ffmpeg_fill_frame(AVFrame* frame, const AUDIO_FORMAT* inputFormat,
 
        return TRUE;
 }
+#if defined(SWRESAMPLE_FOUND)
 static BOOL ffmpeg_decode(AVCodecContext* dec_ctx, AVPacket* pkt,
                           AVFrame* frame,
                           SwrContext* resampleContext,
                           AVFrame* resampled, wStream* out)
+#else
+static BOOL ffmpeg_decode(AVCodecContext* dec_ctx, AVPacket* pkt,
+                          AVFrame* frame,
+                          AVAudioResampleContext* resampleContext,
+                          AVFrame* resampled, wStream* out)
+#endif
 {
        int ret;
        /* send the packet with the compressed data to the decoder */
@@ -445,16 +508,27 @@ static BOOL ffmpeg_decode(AVCodecContext* dec_ctx, AVPacket* pkt,
                        return FALSE;
                }
 
+#if defined(SWRESAMPLE_FOUND)
                if (!swr_is_initialized(resampleContext))
                {
                        if ((ret = swr_config_frame(resampleContext, resampled, frame)) < 0)
                        {
+#else
+               if (!avresample_is_open(resampleContext))
+               {
+                       if ((ret = avresample_config(resampleContext, resampled, frame)) < 0)
+                       {
+#endif
                                const char* err = av_err2str(ret);
                                WLog_ERR(TAG, "Error during resampling %s [%d]", err, ret);
                                return FALSE;
                        }
 
+#if defined(SWRESAMPLE_FOUND)
                        if ((ret = (swr_init(resampleContext))) < 0)
+#else
+                       if ((ret = (avresample_open(resampleContext))) < 0)
+#endif
                        {
                                const char* err = av_err2str(ret);
                                WLog_ERR(TAG, "Error during resampling %s [%d]", err, ret);
@@ -462,7 +536,11 @@ static BOOL ffmpeg_decode(AVCodecContext* dec_ctx, AVPacket* pkt,
                        }
                }
 
+#if defined(SWRESAMPLE_FOUND)
                if ((ret = swr_convert_frame(resampleContext, resampled, frame)) < 0)
+#else
+               if ((ret = avresample_convert_frame(resampleContext, resampled, frame)) < 0)
+#endif
                {
                        const char* err = av_err2str(ret);
                        WLog_ERR(TAG, "Error during resampling %s [%d]", err, ret);
index 498e9cb..d8f2a65 100644 (file)
@@ -32,7 +32,7 @@ Build-Depends:
  libpulse-dev, 
  libavcodec-dev,
  libavutil-dev,
- libswresample-dev,
+ libswresample-dev | libavresample-dev,
  libusb-1.0-0-dev,
  libudev-dev,
  libdbus-glib-1-dev,
index 9595104..63936b6 100644 (file)
@@ -63,7 +63,7 @@ BuildRequires: wayland-devel
 BuildRequires: libjpeg-devel
 BuildRequires: libavutil-devel
 BuildRequires: libavcodec-devel
-BuildRequires: libswresample-devel
+BuildRequires: libswresample-devel || libavresample-devel
 %endif
 # fedora 21+
 %if 0%{?fedora} >= 21 || 0%{?rhel} >= 7