Display and control your Android device
Move all compat ifdefs definitions to compat.h
Romain Vimont751600a7f99f
diff --git a/app/src/compat.h b/app/src/compat.hnew file mode 100644index 00000000..4f709af6--- /dev/null+++ b/app/src/compat.h@@ -0,0 +1,44 @@+#ifndef COMPAT_H+#define COMPAT_H++#include <libavformat/version.h>+#include <SDL2/SDL_version.h>++// In ffmpeg/doc/APIchanges:+// 2016-04-11 - 6f69f7a / 9200514 - lavf 57.33.100 / 57.5.0 - avformat.h+// Add AVStream.codecpar, deprecate AVStream.codec.+#if (LIBAVFORMAT_VERSION_MICRO >= 100 /* FFmpeg */ && \+ LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 33, 100)) \+ || (LIBAVFORMAT_VERSION_MICRO < 100 && /* Libav */ \+ LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 5, 0))+# define SCRCPY_LAVF_HAS_NEW_CODEC_PARAMS_API+#endif++// In ffmpeg/doc/APIchanges:+// 2018-02-06 - 0694d87024 - lavf 58.9.100 - avformat.h+// Deprecate use of av_register_input_format(), av_register_output_format(),+// av_register_all(), av_iformat_next(), av_oformat_next().+// Add av_demuxer_iterate(), and av_muxer_iterate().+#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(58, 9, 100)+# define SCRCPY_LAVF_HAS_NEW_MUXER_ITERATOR_API+#else+# define SCRCPY_LAVF_REQUIRES_REGISTER_ALL+#endif++// In ffmpeg/doc/APIchanges:+// 2016-04-21 - 7fc329e - lavc 57.37.100 - avcodec.h+// Add a new audio/video encoding and decoding API with decoupled input+// and output -- avcodec_send_packet(), avcodec_receive_frame(),+// avcodec_send_frame() and avcodec_receive_packet().+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 37, 100)+# define SCRCPY_LAVF_HAS_NEW_ENCODING_DECODING_API+#endif++#if SDL_VERSION_ATLEAST(2, 0, 5)+// <https://wiki.libsdl.org/SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH>+# define SCRCPY_SDL_HAS_HINT_MOUSE_FOCUS_CLICKTHROUGH+// <https://wiki.libsdl.org/SDL_GetDisplayUsableBounds>+# define SCRCPY_SDL_HAS_GET_DISPLAY_USABLE_BOUNDS+#endif++#endifdiff --git a/app/src/decoder.c b/app/src/decoder.cindex 6e074e7a..9b3ca2f1 100644--- a/app/src/decoder.c+++ b/app/src/decoder.c@@ -8,6 +8,7 @@#include <SDL2/SDL_thread.h>#include <unistd.h>+#include "compat.h"#include "config.h"#include "buffer_util.h"#include "events.h"@@ -220,7 +221,7 @@ static int run_decoder(void *data) {while (!av_read_frame(format_ctx, &packet)) {// the new decoding/encoding API has been introduced by:// <http://git.videolan.org/?p=ffmpeg.git;a=commitdiff;h=7fc329e2dd6226dfecaa4a1d7adf353bf2773726>-#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 37, 0)+#ifdef SCRCPY_LAVF_HAS_NEW_ENCODING_DECODING_APIint ret;if ((ret = avcodec_send_packet(codec_ctx, &packet)) < 0) {LOGE("Could not send video packet: %d", ret);diff --git a/app/src/main.c b/app/src/main.cindex 412dd40a..35bb74ea 100644--- a/app/src/main.c+++ b/app/src/main.c@@ -5,6 +5,7 @@#include <libavformat/avformat.h>#include <SDL2/SDL.h>+#include "compat.h"#include "config.h"#include "log.h"#include "recorder.h"@@ -371,7 +372,7 @@ int main(int argc, char *argv[]) {return 0;}-#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 9, 100)+#ifdef SCRCPY_LAVF_REQUIRES_REGISTER_ALLav_register_all();#endifdiff --git a/app/src/recorder.c b/app/src/recorder.cindex d69953dc..2d47487f 100644--- a/app/src/recorder.c+++ b/app/src/recorder.c@@ -3,28 +3,19 @@#include <libavutil/time.h>#include <SDL2/SDL_assert.h>+#include "compat.h"#include "config.h"#include "log.h"-// In ffmpeg/doc/APIchanges:-// 2016-04-11 - 6f69f7a / 9200514 - lavf 57.33.100 / 57.5.0 - avformat.h-// Add AVStream.codecpar, deprecate AVStream.codec.-#if (LIBAVFORMAT_VERSION_MICRO >= 100 /* FFmpeg */ && \- LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 33, 100)) \- || (LIBAVFORMAT_VERSION_MICRO < 100 && /* Libav */ \- LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 5, 0))-# define LAVF_NEW_CODEC_API-#endif-static const AVRational SCRCPY_TIME_BASE = {1, 1000000}; // timestamps in usstatic const AVOutputFormat *find_muxer(const char *name) {-#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(58, 9, 100)+#ifdef SCRCPY_LAVF_HAS_NEW_MUXER_ITERATOR_APIvoid *opaque = NULL;#endifconst AVOutputFormat *oformat = NULL;do {-#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(58, 9, 100)+#ifdef SCRCPY_LAVF_HAS_NEW_MUXER_ITERATOR_APIoformat = av_muxer_iterate(&opaque);#elseoformat = av_oformat_next(oformat);@@ -91,7 +82,7 @@ SDL_bool recorder_open(struct recorder *recorder, AVCodec *input_codec) {return SDL_FALSE;}-#ifdef LAVF_NEW_CODEC_API+#ifdef SCRCPY_LAVF_HAS_NEW_CODEC_PARAMS_APIostream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;ostream->codecpar->codec_id = input_codec->id;ostream->codecpar->format = AV_PIX_FMT_YUV420P;@@ -144,7 +135,7 @@ recorder_write_header(struct recorder *recorder, AVPacket *packet) {// copy the first packet to the extra datamemcpy(extradata, packet->data, packet->size);-#ifdef LAVF_NEW_CODEC_API+#ifdef SCRCPY_LAVF_HAS_NEW_CODEC_PARAMS_APIostream->codecpar->extradata = extradata;ostream->codecpar->extradata_size = packet->size;#elsediff --git a/app/src/screen.c b/app/src/screen.cindex 42f3114a..4e9752c2 100644--- a/app/src/screen.c+++ b/app/src/screen.c@@ -3,6 +3,7 @@#include <SDL2/SDL.h>#include <string.h>+#include "compat.h"#include "icon.xpm"#include "lock_util.h"#include "log.h"@@ -23,7 +24,7 @@ SDL_bool sdl_init_and_configure(void) {LOGW("Could not enable bilinear filtering");}-#if SDL_VERSION_ATLEAST(2, 0, 5)+#ifdef SCRCPY_SDL_HAS_HINT_MOUSE_FOCUS_CLICKTHROUGH// Handle a click to gain focus as any other clickif (!SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1")) {LOGW("Could not enable mouse focus clickthrough");@@ -71,7 +72,7 @@ static void set_window_size(struct screen *screen, struct size new_size) {// get the preferred display bounds (i.e. the screen bounds with some margins)static SDL_bool get_preferred_display_bounds(struct size *bounds) {SDL_Rect rect;-#if SDL_VERSION_ATLEAST(2, 0, 5)+#ifdef SCRCPY_SDL_HAS_GET_DISPLAY_USABLE_BOUNDS# define GET_DISPLAY_BOUNDS(i, r) SDL_GetDisplayUsableBounds((i), (r))#else# define GET_DISPLAY_BOUNDS(i, r) SDL_GetDisplayBounds((i), (r))