From 17a9fcaafb486549bfc05138a2076b6ae4796f64 Mon Sep 17 00:00:00 2001 From: BtbN Date: Sat, 28 Jun 2014 20:45:10 +0200 Subject: [PATCH] Use propper ffmpeg compatiblity instead of relying on deprecated functions --- libobs/CMakeLists.txt | 3 ++- libobs/graphics/graphics-ffmpeg.c | 6 ++++-- libobs/obs-ffmpeg-compat.h | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 libobs/obs-ffmpeg-compat.h diff --git a/libobs/CMakeLists.txt b/libobs/CMakeLists.txt index a6114374..ed0c8feb 100644 --- a/libobs/CMakeLists.txt +++ b/libobs/CMakeLists.txt @@ -223,7 +223,8 @@ set(libobs_libobs_HEADERS obs-module.h obs-scene.h obs-source.h - obs-output.h) + obs-output.h + obs-ffmpeg-compat.h) set(libobs_SOURCES ${libobs_callback_SOURCES} diff --git a/libobs/graphics/graphics-ffmpeg.c b/libobs/graphics/graphics-ffmpeg.c index 8de82137..4e3c2bb3 100644 --- a/libobs/graphics/graphics-ffmpeg.c +++ b/libobs/graphics/graphics-ffmpeg.c @@ -4,6 +4,8 @@ #include #include +#include "../obs-ffmpeg-compat.h" + struct ffmpeg_image { const char *file; AVFormatContext *fmt_ctx; @@ -121,7 +123,7 @@ static bool ffmpeg_image_decode(struct ffmpeg_image *info, uint8_t *out, { AVPacket packet = {0}; bool success = false; - AVFrame *frame = avcodec_alloc_frame(); + AVFrame *frame = av_frame_alloc(); int got_frame = 0; int ret; @@ -152,7 +154,7 @@ static bool ffmpeg_image_decode(struct ffmpeg_image *info, uint8_t *out, fail: av_free_packet(&packet); - avcodec_free_frame(&frame); + av_frame_free(&frame); return success; } diff --git a/libobs/obs-ffmpeg-compat.h b/libobs/obs-ffmpeg-compat.h new file mode 100644 index 00000000..92289178 --- /dev/null +++ b/libobs/obs-ffmpeg-compat.h @@ -0,0 +1,22 @@ +#pragma once + +#include + +/* LIBAVCODEC_VERSION_CHECK checks for the right version of libav and FFmpeg + * a is the major version + * b and c the minor and micro versions of libav + * d and e the minor and micro versions of FFmpeg */ +#define LIBAVCODEC_VERSION_CHECK( a, b, c, d, e ) \ + ( (LIBAVCODEC_VERSION_MICRO < 100 && LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( a, b, c ) ) || \ + (LIBAVCODEC_VERSION_MICRO >= 100 && LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( a, d, e ) ) ) + +#if !LIBAVCODEC_VERSION_CHECK(54, 28, 0, 59, 100) +# define avcodec_free_frame av_freep +#endif + +#if LIBAVCODEC_VERSION_INT < 0x371c01 +# define av_frame_alloc avcodec_alloc_frame +# define av_frame_unref avcodec_get_frame_defaults +# define av_frame_free avcodec_free_frame +#endif + -- GitLab