Skip to content

Display and control your Android device

Fix compatibility with old FFmpeg

Romain Vimontaf228706f146
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)
// <https://wiki.libsdl.org/SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH>
# 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)
// <https://github.com/FFmpeg/FFmpeg/commit/0694d8702421e7aff1340038559c438b61bb30dd>
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) {