Skip to content

Commit

Permalink
Merge pull request #217 from jstefanelli/master
Browse files Browse the repository at this point in the history
Add basic Android support
  • Loading branch information
tampsa authored May 13, 2024
2 parents b3b1be0 + f5f7157 commit 59351b3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/debug.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include <cstring>
#include <string>

#ifdef ANDROID
#include "android/log.h"
#endif

inline const std::string className(const std::string& prettyFunction)
{
Expand Down Expand Up @@ -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;
Expand All @@ -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__)
Expand Down
9 changes: 9 additions & 0 deletions src/hostname.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ std::string uvgrtp::hostname::get_username()
}

return std::string(buffer);
#elif defined(ANDROID) && __ANDROID_MIN_SDK_VERSION__ < 28
const char* username = getlogin();

if (username == nullptr) {
UVG_LOG_ERROR("%s", strerror(errno));
return "";
}

return std::string(username);
#else
char username[NAME_MAXLEN];

Expand Down

0 comments on commit 59351b3

Please sign in to comment.