Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic Android support #217

Merged
merged 4 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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