瀏覽代碼

Use propper ffmpeg compatiblity instead of relying on deprecated functions

BtbN 11 年之前
父節點
當前提交
17a9fcaafb
共有 3 個文件被更改,包括 28 次插入3 次删除
  1. 2 1
      libobs/CMakeLists.txt
  2. 4 2
      libobs/graphics/graphics-ffmpeg.c
  3. 22 0
      libobs/obs-ffmpeg-compat.h

+ 2 - 1
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}

+ 4 - 2
libobs/graphics/graphics-ffmpeg.c

@@ -4,6 +4,8 @@
 #include <libavformat/avformat.h>
 #include <libswscale/swscale.h>
 
+#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;
 }
 

+ 22 - 0
libobs/obs-ffmpeg-compat.h

@@ -0,0 +1,22 @@
+#pragma once
+
+#include <libavcodec/avcodec.h>
+
+/* 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
+