Skip to content

Commit

Permalink
Readded AVRESAMPLE support as fallback.
Browse files Browse the repository at this point in the history
  • Loading branch information
akallabeth committed Oct 4, 2018
1 parent 41cc2b6 commit fbe9520
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 8 deletions.
23 changes: 18 additions & 5 deletions cmake/FindFFmpeg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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})
Expand All @@ -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)
2 changes: 2 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

/* Features */
#cmakedefine HAVE_ALIGNED_REQUIRED
#cmakedefine SWRESAMPLE_FOUND
#cmakedefine AVRESAMPLE_FOUND

/* Options */
#cmakedefine WITH_PROFILER
Expand Down
80 changes: 79 additions & 1 deletion libfreerdp/codec/dsp_ffmpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@
#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"
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -322,6 +342,8 @@ static BOOL ffmpeg_open_context(FREERDP_DSP_CONTEXT* context)
ffmpeg_close_context(context);
return FALSE;
}

#if defined(SWRESAMPLE_FOUND)
static BOOL ffmpeg_resample_frame(SwrContext* context,
AVFrame* in, AVFrame* out)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -445,24 +508,39 @@ 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);
return FALSE;
}
}

#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);
Expand Down
2 changes: 1 addition & 1 deletion packaging/deb/freerdp-nightly/control
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packaging/rpm/freerdp-nightly.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fbe9520

Please sign in to comment.