From 751600a7f99fb9910e96f0f29be427622c932441 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sat, 16 Feb 2019 15:04:32 +0100 Subject: [PATCH] Move all compat ifdefs definitions to compat.h This allows to give a proper name to features requirements. --- app/src/compat.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ app/src/decoder.c | 3 ++- app/src/main.c | 3 ++- app/src/recorder.c | 19 +++++-------------- app/src/screen.c | 5 +++-- 5 files changed, 56 insertions(+), 18 deletions(-) create mode 100644 app/src/compat.h diff --git a/app/src/compat.h b/app/src/compat.h new file mode 100644 index 00000000..4f709af6 --- /dev/null +++ b/app/src/compat.h @@ -0,0 +1,44 @@ +#ifndef COMPAT_H +#define COMPAT_H + +#include +#include + +// 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) +// +# define SCRCPY_SDL_HAS_HINT_MOUSE_FOCUS_CLICKTHROUGH +// +# define SCRCPY_SDL_HAS_GET_DISPLAY_USABLE_BOUNDS +#endif + +#endif diff --git a/app/src/decoder.c b/app/src/decoder.c index 6e074e7a..9b3ca2f1 100644 --- a/app/src/decoder.c +++ b/app/src/decoder.c @@ -8,6 +8,7 @@ #include #include +#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: // -#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 37, 0) +#ifdef SCRCPY_LAVF_HAS_NEW_ENCODING_DECODING_API int 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.c index 412dd40a..35bb74ea 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -5,6 +5,7 @@ #include #include +#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_ALL av_register_all(); #endif diff --git a/app/src/recorder.c b/app/src/recorder.c index d69953dc..2d47487f 100644 --- a/app/src/recorder.c +++ b/app/src/recorder.c @@ -3,28 +3,19 @@ #include #include +#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 us static const AVOutputFormat *find_muxer(const char *name) { -#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(58, 9, 100) +#ifdef SCRCPY_LAVF_HAS_NEW_MUXER_ITERATOR_API void *opaque = NULL; #endif const AVOutputFormat *oformat = NULL; do { -#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(58, 9, 100) +#ifdef SCRCPY_LAVF_HAS_NEW_MUXER_ITERATOR_API oformat = av_muxer_iterate(&opaque); #else oformat = 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_API ostream->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 data memcpy(extradata, packet->data, packet->size); -#ifdef LAVF_NEW_CODEC_API +#ifdef SCRCPY_LAVF_HAS_NEW_CODEC_PARAMS_API ostream->codecpar->extradata = extradata; ostream->codecpar->extradata_size = packet->size; #else diff --git a/app/src/screen.c b/app/src/screen.c index 42f3114a..4e9752c2 100644 --- a/app/src/screen.c +++ b/app/src/screen.c @@ -3,6 +3,7 @@ #include #include +#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 click if (!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))