From f2db5fdb39bf1de2511857551a9c6d7916ede102 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Sat, 26 Jan 2019 11:50:21 -0500 Subject: [PATCH 1/2] FFmpegUtilities: Rename RSHIFT to FF_RSHIFT FFmpeg and Ruby have competing definitions of the RSHIFT macro, so building the Ruby bindings causes warnings to be thrown when it's redefined. This change defines FF_RSHIFT to replace FFmpeg's RSHIFT, which is undef'd --- include/FFmpegUtilities.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/FFmpegUtilities.h b/include/FFmpegUtilities.h index 346da541..e16466e3 100644 --- a/include/FFmpegUtilities.h +++ b/include/FFmpegUtilities.h @@ -114,6 +114,13 @@ #define PIX_FMT_YUV420P AV_PIX_FMT_YUV420P #endif + // FFmpeg's libavutil/common.h defines an RSHIFT incompatible with Ruby's + // definition in ruby/config.h, so we move it to FF_RSHIFT + #ifdef RSHIFT + #define FF_RSHIFT(a, b) RSHIFT(a, b) + #undef RSHIFT + #endif + #ifdef USE_SW #define SWR_CONVERT(ctx, out, linesize, out_count, in, linesize2, in_count) \ swr_convert(ctx, out, out_count, (const uint8_t **)in, in_count) From bb8efeb72b55d093349d950f533f32b1243d0852 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Sat, 26 Jan 2019 11:53:08 -0500 Subject: [PATCH 2/2] Ruby: Rename RSHIFT to RB_RSHIFT, temporarily When Ruby attempts to load the FFmpeg header files, it'll complain that RSHIFT is redefined if the Ruby definition is still in place. So, we define RB_RSHIFT to contain the Ruby definition, undef RSHIFT, load the FFmpeg headers, move its RSHIFT into FF_RSHIFT if necessary, and then restore Ruby's RSHIFT from RB_RSHIFT. --- src/bindings/ruby/openshot.i | 39 +++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/bindings/ruby/openshot.i b/src/bindings/ruby/openshot.i index b9a35d41..82925b71 100644 --- a/src/bindings/ruby/openshot.i +++ b/src/bindings/ruby/openshot.i @@ -57,6 +57,14 @@ namespace std { %{ +/* Ruby and FFmpeg define competing RSHIFT macros, + * so we move Ruby's out of the way for now. We'll + * restore it after dealing with FFmpeg's + */ +#ifdef RSHIFT + #define RB_RSHIFT(a, b) RSHIFT(a, b) + #undef RSHIFT +#endif #include "../../../include/Version.h" #include "../../../include/ReaderBase.h" #include "../../../include/WriterBase.h" @@ -91,7 +99,15 @@ namespace std { #include "../../../include/Settings.h" #include "../../../include/Timeline.h" #include "../../../include/ZmqLogger.h" - +/* Move FFmpeg's RSHIFT to FF_RSHIFT, if present */ +#ifdef RSHIFT + #define FF_RSHIFT(a, b) RSHIFT(a, b) + #undef RSHIFT +#endif +/* And restore Ruby's RSHIFT, if we captured it */ +#ifdef RB_RSHIFT + #define RSHIFT(a, b) RB_RSHIFT(a, b) +#endif %} #ifdef USE_BLACKMAGIC @@ -132,8 +148,29 @@ namespace std { %include "../../../include/EffectInfo.h" %include "../../../include/Enums.h" %include "../../../include/Exceptions.h" + +/* Ruby and FFmpeg define competing RSHIFT macros, + * so we move Ruby's out of the way for now. We'll + * restore it after dealing with FFmpeg's + */ +#ifdef RSHIFT + #define RB_RSHIFT(a, b) RSHIFT(a, b) + #undef RSHIFT +#endif + %include "../../../include/FFmpegReader.h" %include "../../../include/FFmpegWriter.h" + +/* Move FFmpeg's RSHIFT to FF_RSHIFT, if present */ +#ifdef RSHIFT + #define FF_RSHIFT(a, b) RSHIFT(a, b) + #undef RSHIFT +#endif +/* And restore Ruby's RSHIFT, if we captured it */ +#ifdef RB_RSHIFT + #define RSHIFT(a, b) RB_RSHIFT(a, b) +#endif + %include "../../../include/Fraction.h" %include "../../../include/Frame.h" %include "../../../include/FrameMapper.h"