From 4c592e5b330e1df47c78f9ffb0a46b9103692d6f Mon Sep 17 00:00:00 2001 From: jstefanelli Date: Wed, 17 Apr 2024 17:14:39 +0200 Subject: [PATCH 1/4] Fix compilation for old Android NDK/SDK --- src/hostname.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/hostname.cc b/src/hostname.cc index 388d40a9..328c3595 100644 --- a/src/hostname.cc +++ b/src/hostname.cc @@ -48,6 +48,16 @@ std::string uvgrtp::hostname::get_username() } return std::string(buffer); +#else +#ifdef ANDROID + const char* username = getlogin(); + + if (username == nullptr) { + UVG_LOG_ERROR("%s", strerror(errno)); + return ""; + } + + return std::string(username); #else char username[NAME_MAXLEN]; @@ -58,4 +68,5 @@ std::string uvgrtp::hostname::get_username() return std::string(username); #endif +#endif } From ff00a0ac216d105e025b2fb78a8389903d6c2676 Mon Sep 17 00:00:00 2001 From: jstefanelli Date: Tue, 7 May 2024 12:46:35 +0200 Subject: [PATCH 2/4] Output UVG_LOG_*** messages to Android Logcat when targeting Android --- src/debug.hh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/debug.hh b/src/debug.hh index e5514e59..1600e023 100644 --- a/src/debug.hh +++ b/src/debug.hh @@ -11,6 +11,9 @@ #include #include +#ifdef ANDROID +#include "android/log.h" +#endif inline const std::string className(const std::string& prettyFunction) { @@ -50,7 +53,27 @@ static inline void win_get_last_error(void) #define LOG_LEVEL_INFO "\x1b[34mINFO\x1b[0m" #endif #define LOG_LEVEL_DEBUG "DEBUG" +#ifdef ANDROID +static inline void uvgrtp_debug(const char *level, const char *function, const char *s, ...) +{ + android_LogPriority android_level = android_LogPriority::ANDROID_LOG_DEBUG; + if (strcmp(level, LOG_LEVEL_ERROR) == 0) { + android_level = android_LogPriority::ANDROID_LOG_ERROR; + } else if (strcmp(level, LOG_LEVEL_WARN) == 0) { + android_level = android_LogPriority::ANDROID_LOG_WARN; + } else if (strcmp(level, LOG_LEVEL_INFO) == 0) { + android_level = android_LogPriority::ANDROID_LOG_INFO; + } + va_list args; + va_start(args, s); + char fmt[256] = {0}; + snprintf(fmt, sizeof(fmt), "[uvgRTP][%s::%s] %s\n", + "", function, s); + __android_log_vprint(android_level, "UVGRTP", fmt, args); + va_end(args); +} +#else static inline void uvgrtp_debug(const char *level, const char *function, const char *s, ...) { va_list args; @@ -61,6 +84,7 @@ static inline void uvgrtp_debug(const char *level, const char *function, const c vfprintf(stderr, fmt, args); va_end(args); } +#endif #ifndef NDEBUG #define UVG_LOG_DEBUG(...) uvgrtp_debug(LOG_LEVEL_DEBUG, __func__, __VA_ARGS__) From 23fefd718e92e2cb181cacc7624c8fa840e83308 Mon Sep 17 00:00:00 2001 From: jstefanelli Date: Tue, 7 May 2024 12:47:35 +0200 Subject: [PATCH 3/4] Remove nested ifdef for Android hostname fix --- src/hostname.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/hostname.cc b/src/hostname.cc index 328c3595..702c4dd0 100644 --- a/src/hostname.cc +++ b/src/hostname.cc @@ -48,8 +48,7 @@ std::string uvgrtp::hostname::get_username() } return std::string(buffer); -#else -#ifdef ANDROID +#elif defined(ANDROID) const char* username = getlogin(); if (username == nullptr) { @@ -68,5 +67,4 @@ std::string uvgrtp::hostname::get_username() return std::string(username); #endif -#endif } From f5f7157ffa2fe36d74b59cebef97be29e84256a9 Mon Sep 17 00:00:00 2001 From: jstefanelli Date: Tue, 7 May 2024 12:56:34 +0200 Subject: [PATCH 4/4] Apply Android hostname fix only for Android min SDK version < 28 --- src/hostname.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hostname.cc b/src/hostname.cc index 702c4dd0..d0c66a95 100644 --- a/src/hostname.cc +++ b/src/hostname.cc @@ -48,7 +48,7 @@ std::string uvgrtp::hostname::get_username() } return std::string(buffer); -#elif defined(ANDROID) +#elif defined(ANDROID) && __ANDROID_MIN_SDK_VERSION__ < 28 const char* username = getlogin(); if (username == nullptr) {