From af228706f14696e818f4004691d4de0006ac4910 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sun, 13 Jun 2021 18:31:48 +0200 Subject: [PATCH] Fix compatibility with old FFmpeg V4L2 sink used a "url" field format AVFormatContext which has been introduced in lavf 58.7.100. Fixes #2382 Refs Refs --- app/src/compat.h | 12 ++++++++++++ app/src/v4l2_sink.c | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/app/src/compat.h b/app/src/compat.h index 9d9a7884..8e2d18f4 100644 --- a/app/src/compat.h +++ b/app/src/compat.h @@ -22,6 +22,18 @@ # define SCRCPY_LAVF_REQUIRES_REGISTER_ALL #endif + +// In ffmpeg/doc/APIchanges: +// 2018-01-28 - ea3672b7d6 - lavf 58.7.100 - avformat.h +// Deprecate AVFormatContext filename field which had limited length, use the +// new dynamically allocated url field instead. +// +// 2018-01-28 - ea3672b7d6 - lavf 58.7.100 - avformat.h +// Add url field to AVFormatContext and add ff_format_set_url helper function. +#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(58, 7, 100) +# define SCRCPY_LAVF_HAS_AVFORMATCONTEXT_URL +#endif + #if SDL_VERSION_ATLEAST(2, 0, 5) // # define SCRCPY_SDL_HAS_HINT_MOUSE_FOCUS_CLICKTHROUGH diff --git a/app/src/v4l2_sink.c b/app/src/v4l2_sink.c index fd0bda12..d7c1a667 100644 --- a/app/src/v4l2_sink.c +++ b/app/src/v4l2_sink.c @@ -180,12 +180,17 @@ sc_v4l2_sink_open(struct sc_v4l2_sink *vs) { // still expects a pointer-to-non-const (it has not be updated accordingly) // vs->format_ctx->oformat = (AVOutputFormat *) format; +#ifdef SCRCPY_LAVF_HAS_AVFORMATCONTEXT_URL vs->format_ctx->url = strdup(vs->device_name); if (!vs->format_ctx->url) { LOGE("Could not strdup v4l2 device name"); goto error_avformat_free_context; return false; } +#else + strncpy(vs->format_ctx->filename, vs->device_name, + sizeof(vs->format_ctx->filename)); +#endif AVStream *ostream = avformat_new_stream(vs->format_ctx, encoder); if (!ostream) {